#pragma once

struct GLTextureDesc
{
	std::string		name;
	uint	width;
	uint	height;
	GLenum			internalFormat;
	GLenum			format;
	GLenum			type;
	void*			data;
};

struct GLTexture
{
	const std::string name;
	uint handle;
	glm::vec2 size;

	GLTexture(const std::string& name) :
		handle(0),
		name(name)
	{}
};

struct GLTextureContainer
{
	GLTextureContainer(GLTexture* texture) :
		texture(texture)
	{}

	GLTexture* texture;
};

class TextureWrapper
{
protected:
	TextureWrapper();
	~TextureWrapper();

	static GLTexture**	_boundTextures;
	static int			_texturesCount;
	static std::map<std::string, GLTexture*>			_texturesMap;
	static std::map<std::string, GLTextureContainer*>	_samplerMap;

public:
	static GLTexture*	GenTexture(const GLTextureDesc* desc);
	static GLTexture*	GenTexture(const std::string& name, const std::string& path);

	static void			DeleteTexture(GLTexture** t);
	static void			BindTextureAt(uint i, GLTexture* t, bool force = false);
	static void			UnbindTextureAt(uint i);
	static void			UnbindTextures();
	static GLTexture**	GetBoundTextures();

	static void			LoadTextureFromFile(GLTexture* t, const std::string& path);

	static void			SetSampler(const std::string& name, GLTexture* texture);
	static GLTexture**	GetSampler(const std::string& name);

	static void			SaveScreenshot(const std::string& path, const glm::ivec2& pos, const glm::ivec2& size);
	static GLTexture*	GetTexture(const std::string& name);
};

